home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / arp.h < prev    next >
C/C++ Source or Header  |  1994-06-04  |  5KB  |  145 lines

  1. /* Mods by PA0GRI */
  2. #ifndef    _ARP_H
  3. #define    _ARP_H
  4.  
  5. #ifndef    _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.  
  9. #ifndef    _MBUF_H
  10. #include "mbuf.h"
  11. #endif
  12.  
  13. #ifndef    _IFACE_H
  14. #include "iface.h"
  15. #endif
  16.  
  17. #ifndef    _TIMER_H
  18. #include "timer.h"
  19. #endif
  20.  
  21. /* Lifetime of a valid ARP entry */
  22. #define    ARPLIFE        900    /* 15 minutes */
  23. /* Lifetime of a pending ARP entry */
  24. #define    PENDTIME    15    /* 15 seconds */
  25. /* Maximum number of datagrams in queue while pending an resolution */
  26. #define ARP_QUEUE   5   /* 5 packets max on queue */
  27.  
  28. /* ARP definitions (see RFC 826) */
  29.  
  30. #define    ARPLEN    16        /* Size of ARP hdr, minus hardware addresses */
  31.  
  32. /* Address size definitions */
  33. #define    IPALEN    4        /* Length in bytes of an IP address */
  34. #define    MAXHWALEN    255    /* Maximum length of a hardware address */
  35.  
  36. /* ARP opcodes */
  37. #define    ARP_REQUEST    1
  38. #define    ARP_REPLY    2
  39. #define    REVARP_REQUEST    3
  40. #define    REVARP_REPLY    4
  41.  
  42. /* Hardware types */
  43. #define    ARP_NETROM    0    /* Fake for NET/ROM (never actually sent) */
  44. #define    ARP_ETHER    1    /* Assigned to 10 megabit Ethernet */
  45. #define    ARP_EETHER    2    /* Assigned to experimental Ethernet */
  46. #define    ARP_AX25    3    /* Assigned to AX.25 Level 2 */
  47. #define    ARP_PRONET    4    /* Assigned to PROnet token ring */
  48. #define    ARP_CHAOS    5    /* Assigned to Chaosnet */
  49. #define    ARP_IEEE802    6    /* Who uses this? */
  50. #define    ARP_ARCNET    7
  51. #define    ARP_APPLETALK    8
  52. extern char *Arptypes[];    /* Type fields in ASCII, defined in arpcmd */
  53. #define    NHWTYPES 9
  54.  
  55. /* Table of hardware types known to ARP */
  56. struct arp_type {
  57.     int16 hwalen;        /* Hardware length */
  58.     int16 iptype;        /* Hardware type field for IP */
  59.     int16 arptype;        /* Hardware type field for ARP */
  60.     int16 rarptype;        /* Hardware type field for RARP */
  61.     int16 pendtime;        /* # secs to wait pending response */
  62.     char *bdcst;        /* Hardware broadcast address */
  63.     char *(*format) __ARGS((char *,char *));
  64.                 /* Function that formats addresses */
  65.     int (*scan) __ARGS((char *,char *));
  66.                 /* Reverse of format */
  67. };
  68. extern struct arp_type far Arp_type[];
  69. #define    NULLATYPE    (struct arp_type *)0
  70.  
  71. /* Format of an ARP request or reply packet. From p. 3 */
  72. struct arp {
  73.     int16 hardware;            /* Hardware type */
  74.     int16 protocol;            /* Protocol type */
  75.     char hwalen;            /* Hardware address length, bytes */
  76.     char pralen;            /* Length of protocol address */
  77.     int16 opcode;            /* ARP opcode (request/reply) */
  78.     char shwaddr[MAXHWALEN];    /* Sender hardware address field */
  79.     int32 sprotaddr;        /* Sender Protocol address field */
  80.     char thwaddr[MAXHWALEN];    /* Target hardware address field */
  81.     int32 tprotaddr;        /* Target protocol address field */
  82. };
  83.         
  84. /* Format of ARP table */
  85. struct arp_tab {
  86.     struct arp_tab *next;    /* Doubly-linked list pointers */
  87.     struct arp_tab *prev;    
  88.     struct timer timer;    /* Time until aging this entry */
  89.     struct mbuf *pending;    /* Queue of datagrams awaiting resolution */
  90.     int32 ip_addr;        /* IP Address, host order */
  91.     int16 hardware;        /* Hardware type */
  92.     char state;        /* (In)complete */
  93. #define    ARP_PENDING    0
  94. #define    ARP_VALID    1
  95.     char pub;        /* Respond to requests for this entry? */
  96.     char *hw_addr;        /* Hardware address */
  97.     struct iface *iface;    /* Interface to use route on -- sm6rpz */
  98. };
  99. #define    NULLARP    (struct arp_tab *)0
  100. extern struct arp_tab *Arp_tab[];
  101.  
  102. #ifdef UNIX
  103. #ifndef recv
  104. /* hack; we #define'd recv to j_recv to avoid stdc botch, so we need it here
  105.    else some things call this arp_stat.recv and others arp_stat.j_recv! */
  106. #include "socket.h"
  107. #endif
  108. #endif
  109. struct arp_stat {
  110.     unsigned recv;        /* Total number of ARP packets received */
  111.     unsigned badtype;    /* Incoming requests for unsupported hardware */
  112.     unsigned badlen;    /* Incoming length field(s) didn't match types */
  113.     unsigned badaddr;    /* Bogus incoming addresses */
  114.     unsigned inreq;        /* Incoming requests for us */
  115.     unsigned replies;    /* Replies sent */
  116.     unsigned outreq;    /* Outoging requests sent */
  117. };
  118. extern struct arp_stat Arp_stat, Rarp_stat;
  119.  
  120. /* In arp.c: */
  121. struct arp_tab *arp_add __ARGS((int32 ipaddr,int16 hardware,char *hw_addr,
  122.     int pub,struct iface *iface));
  123. void arp_drop __ARGS((void *p));
  124. int arp_init __ARGS((unsigned int hwtype,int hwalen,int iptype,int arptype,
  125.     int pendtime,char *bdcst,char *(*format) __ARGS((char *,char *)),
  126.     int  (*scan) __ARGS((char *,char *)) ));
  127. void arp_input __ARGS((struct iface *iface,struct mbuf *bp));
  128. struct arp_tab *arp_lookup __ARGS((int16 hardware,int32 ipaddr,struct iface *iface));
  129. char *res_arp __ARGS((struct iface *iface,int16 hardware,int32 target,struct mbuf *bp));
  130.  
  131. /* In arphdr.c: */
  132. struct mbuf *htonarp __ARGS((struct arp *arp));
  133. int ntoharp __ARGS((struct arp *arp,struct mbuf **bpp));
  134.  
  135. /* In rarp.c: */
  136. void rarp_input __ARGS((struct iface *iface,struct mbuf *bp));
  137.  
  138. #ifdef UNIX
  139. /* should this be being used by non-ethernet-specific code? (arp.c) */
  140. /* (ans: no.  this could cause problems if rarp used on ax.25...) */
  141. #define REVARP_TYPE     0x8035
  142. #endif
  143.  
  144. #endif /* _ARP_H */
  145.